package com.example.backend.controller;

import com.example.backend.entity.ResponseMessage;
import com.example.backend.service.StatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
public class StatisticsController {

    @Autowired
    private StatisticsService statisticsService;

    // 获取总用户数
    @GetMapping("/statistics/user-count")
    public ResponseMessage getUserCount() {
        int count = statisticsService.getUserCount();
        return ResponseMessage.success(count);
    }

    // 获取总商家数
    @GetMapping("/statistics/shop-count")
    public ResponseMessage getShopCount() {
        int count = statisticsService.getShopCount();
        return ResponseMessage.success(count);
    }

    // 获取总订单数
    @GetMapping("/statistics/order-count")
    public ResponseMessage getOrderCount() {
        int count = statisticsService.getOrderCount();
        return ResponseMessage.success(count);
    }

    // 获取已完成订单数
    @GetMapping("/statistics/completed-order-count")
    public ResponseMessage getCompletedOrderCount() {
        int count = statisticsService.getCompletedOrderCount();
        return ResponseMessage.success(count);
    }

    // 获取总销售额
    @GetMapping("/statistics/total-sales")
    public ResponseMessage getTotalSales() {
        double sales = statisticsService.getTotalSales();
        return ResponseMessage.success(sales);
    }

    // 获取订单趋势数据
    @GetMapping("/statistics/order-trend")
    public ResponseMessage getOrderTrend() {
        List<Map<String, Object>> trend = statisticsService.getOrderTrend();
        return ResponseMessage.success(trend);
    }

    // 获取销售趋势数据
    @GetMapping("/statistics/sales-trend")
    public ResponseMessage getSalesTrend() {
        List<Map<String, Object>> trend = statisticsService.getSalesTrend();
        return ResponseMessage.success(trend);
    }
    // 获取商家地理分布数据
    @GetMapping("/statistics/shop-geo-distribution")
    public ResponseMessage getShopGeoDistribution() {
        List<Map<String, Object>> distribution = statisticsService.getShopGeoDistribution();
        return ResponseMessage.success(distribution);
    }

//    // 获取用户性别分布数据
//    @GetMapping("/statistics/user-gender")
//    public ResponseMessage getUserGenderDistribution() {
//        List<Map<String, Object>> distribution = statisticsService.getUserGenderDistribution();
//        return ResponseMessage.success(distribution);
//    }

    // 获取用户年龄分布数据
    @GetMapping("/statistics/user-age")
    public ResponseMessage getUserAgeDistribution() {
        List<Map<String, Object>> distribution = statisticsService.getUserAgeDistribution();
        return ResponseMessage.success(distribution);
    }
}